package webEquipeRechercheGwt.client.handler.creation.link.seminar;

import java.util.List;

import webEquipeRechercheGwt.client.callback.creation.CallBackSeminarCreationAndModification;
import webEquipeRechercheGwt.client.entityMirror.SeminarMirror;
import webEquipeRechercheGwt.client.entityMirror.PersonMirror;
import webEquipeRechercheGwt.client.services.LinkingService;
import webEquipeRechercheGwt.client.services.LinkingServiceAsync;
import webEquipeRechercheGwt.client.structure.DataShowingPanel;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ListBox;

public class ClickHandlerSeminarToPersonLink implements ClickHandler {
	
	private List<PersonMirror> list;
	private ListBox listBox;
	private SeminarMirror target;
	private DataShowingPanel mainPanel;

	public ClickHandlerSeminarToPersonLink(List<PersonMirror> list,
			ListBox listBox, SeminarMirror target, DataShowingPanel mainPanel) {
		this.list = list;
		this.listBox = listBox;
		this.target = target;
		this.mainPanel = mainPanel;
	}

	@Override
	public void onClick(ClickEvent event) {
		int listBoxIndex = listBox.getSelectedIndex();
		PersonMirror added = list.get(listBoxIndex);
		
		LinkingServiceAsync service = GWT.create(LinkingService.class);
		AsyncCallback<Boolean> callback = new CallBackSeminarCreationAndModification(mainPanel);
		service.linkPersonToSeminar(added, target, callback);
	}

}